package com.cyan.app.workflow.util;

import com.cyan.app.workflow.AppData;
import java.util.Map;

/**
 * Created by GivenTang on 2015/5/27.
 */
public class ParamUtils {

    /**
     * GET请求添加公共参数
     * @param map
     * @return
     */
    public static Map<String, String> getRequestParamGet(Map<String, String> map) {
        if(map != null) {
            map.put("pcode", "android");
            map.put("identid", AppData.UUID);
            map.put("userid", AppData.getInstance().getUserId());
        }
        return map;
    }

    /**
     * POST请求添加公共参数
     * @param map
     * @return
     */
    public static Map<String, String> getRequestParamPost(Map<String, String> map) {
        if(map != null) {
            map.put("uuid", AppData.UUID);
            map.put("platformCode", "Android");
            map.put("platformVersion", android.os.Build.VERSION.RELEASE);
            map.put("appVersion", AppData.APPVERSION);
            map.put("UserID", AppData.getInstance().getUserId());
            map.put("usertype", AppData.getInstance().getUserType());
            map.put("token", AppData.getInstance().getUserToken());
        }
        return map;
    }

    /**
     * 参数类型MAP转STRING
     * @param params
     * @return
     */
    public static String mapToStringParams(Map<String, String> params) {
        String queryString = "";
        if (params != null) {
            for (String key : params.keySet()) {
                String value = params.get(key);
                queryString += key + "=" + (value == null ? "" : value) + "&";
            }
        }
        if (queryString.length() > 0) {
            queryString = queryString.substring(0, queryString.length() - 1);
        }
        return queryString;
    }
}
